package org.inspursc.s0517.health.common.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.inspursc.s0517.health.common.dao.SysPermissionGroupDao;
import org.inspursc.s0517.health.common.entity.SysPermissionGroup;
import org.inspursc.s0517.health.common.service.SysPermissionGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Slf4j
public class SysPermissionGroupServiceImpl implements SysPermissionGroupService {

    @Autowired
    private SysPermissionGroupDao permissionGroupDao;

    @Override
    public SysPermissionGroup save(SysPermissionGroup permissionGroup) {
        return permissionGroupDao.save(permissionGroup);
    }

    @Override
    public List<SysPermissionGroup> findPermissionByGroupId(Integer groupId) {
        return permissionGroupDao.findBySysGroupId(groupId);
    }

    @Override
    @Transactional
    public boolean deleteByGroupId(Integer groupId) {
        try {
            permissionGroupDao.deleteById(groupId);
            return true;
        } catch (Exception e) {
            log.error("【删除失败】", e.getMessage());
            return false;
        }
    }
}
